#include "stdafx.h"
//-------------------------------------------------------------------------------------------------
//ImageTypeProp.cpp  - a property for a particular ImageType 
//	typically an ImageType has one or more properties that a user can edit in the Property Window (top part)        
//-------------------------------------------------------------------------------------------------
//FreeBSD License
//Copyright 2011 Will Stott All rights reserved.
//
//Redistribution and use in source and binary forms, with or without modification, are
//permitted provided that the following conditions are met:
//
//   1. Redistributions of source code must retain the above copyright notice, this list of
//      conditions and the following disclaimer.
//
//   2. Redistributions in binary form must reproduce the above copyright notice, this list
//      of conditions and the following disclaimer in the documentation and/or other materials
//      provided with the distribution.
//
//THIS SOFTWARE IS PROVIDED BY Will Stott ``AS IS'' AND ANY EXPRESS OR IMPLIED
//WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
//FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Will Stott OR
//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
//CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
//ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
//ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//The views and conclusions contained in the software and documentation are those of the
//authors and should not be interpreted as representing official policies, either expressed
//or implied, of Will Stott.
//
//----Authors--------------------------------------------------------------------------------------
//created by: will.stott@ucl.ac.uk Sept 2011
//
//----Comments-------------------------------------------------------------------------------------
//
//-------------------------------------------------------------------------------------------------
#include <assert.h>

#include "ImageTypeProp.h"
#include "ImageType.h"
#include "ImageDataset.h"


const char * const ImageTypeProp::xmlType = "Type";
const char * const ImageTypeProp::xmlControl = "Control";
const char * const ImageTypeProp::xmlValMin = "ValMin";
const char * const ImageTypeProp::xmlValMax = "ValMax";
const char * const ImageTypeProp::xmlPrompt = "Prompt";
const char * const ImageTypeProp::xmlDefaultValue = "DefaultValue";


ImageTypeProp::ImageTypeProp(void):
	_OwnerType(ImageType::xmlImageType),
	_Name(""),
	_Type(""),	
	_Control(""),	
	_Prompt(""),	
	_ValMin(-1),
	_ValMax(-1),
	_DefaultValue("")
{
}

ImageTypeProp::~ImageTypeProp(void)
{
}

ImageTypeProp *ImageTypeProp::CreateImageTypeProp(TiXmlElement *xmlImageTypeProp, const char *ownerTypeName)
{
	ImageTypeProp *rc = '\0';

	//<ImageTypeProp Type="PropTextLines" Control="CEdit" ValMin="-1" ValMax="500" Prompt="Enter text to describe image">Notes</ImageTypeProp>

	if ( xmlImageTypeProp != '\0')
	{
		rc = new ImageTypeProp();

		assert(rc->SetOwnerTypeName(ownerTypeName)); 

		std::string attribName = xmlImageTypeProp->GetText();
		rc->SetName(ImageDataset::MakeWellFormedAttributeName(attribName));

		rc->SetType(xmlImageTypeProp->Attribute(ImageTypeProp::xmlType));
		rc->SetControl(xmlImageTypeProp->Attribute(ImageTypeProp::xmlControl));
		rc->SetValMin(xmlImageTypeProp->Attribute(ImageTypeProp::xmlValMin));
		rc->SetValMax(xmlImageTypeProp->Attribute(ImageTypeProp::xmlValMax));
		rc->SetPrompt(xmlImageTypeProp->Attribute(ImageTypeProp::xmlPrompt));
		rc->SetDefaultValue(xmlImageTypeProp->Attribute(ImageTypeProp::xmlDefaultValue));
	}

	return rc;
}

bool  ImageTypeProp::SetOwnerTypeName(const char *ownerTypeName)
{  
	bool rc = false;

	std::string name = ownerTypeName;

	if (name == ImageType::xmlImageTypeImageObject)
	{
		_OwnerType = ImageType::xmlImageTypeImageObject;
		rc = true;
	}
	if (name == ImageType::xmlImageType)
	{
		_OwnerType = ImageType::xmlImageType;
		rc = true;
	}

	return rc;

}

void ImageTypeProp::SetValMin(const char *valMin)
{
	if (valMin == '\0')
		_ValMin = 0;
	else
	{
		_ValMin = std::atoi(valMin);
	}
}

void ImageTypeProp::SetValMax(const char *valMax)
{
	if (valMax == '\0')
		_ValMax = 0;
	else
	{
		_ValMax = std::atoi(valMax);
	}
}

//-------------------------------------------------------------------------------------------------
//			E N D   O F   F I L E
//-------------------------------------------------------------------------------------------------